package com.slkj.shilixiaoyuanapp.ui.teacher.tool.reimbursement;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.api.InjectParam;
import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.base.ActivityInfo;
import com.slkj.shilixiaoyuanapp.base.BaseActivity;
import com.slkj.shilixiaoyuanapp.data.LeaveTypeData;
import com.slkj.shilixiaoyuanapp.data.UserRequest;
import com.slkj.shilixiaoyuanapp.entity.BxDetailEntity;
import com.slkj.shilixiaoyuanapp.net.HttpHeper;
import com.slkj.shilixiaoyuanapp.net.callback.CommonCallBack;
import com.slkj.shilixiaoyuanapp.ui.common.ChosePeopleActivity;
import com.slkj.shilixiaoyuanapp.ui.common.adapter.ChosePicAdapter;
import com.slkj.shilixiaoyuanapp.view.NumberEditText;
import com.slkj.shilixiaoyuanapp.view.dialog.LoadSuccessAndFailDialog;

import butterknife.BindView;
import butterknife.OnClick;

import static com.slkj.shilixiaoyuanapp.entity.code.UiCode.CHOSE_PIC_SPAN_COUNT;

@ActivityInfo(layout = R.layout.activity_reimbursement_dsp_activity, title = "待审批")
public class ReimbursementDspActivityActivity extends BaseActivity {
    @InjectParam
    int  id;
    @InjectParam
    BxDetailEntity data;
    @BindView(R.id.recyc_pic)
    RecyclerView recycerPic;
    @BindView(R.id.tv_type)
    TextView tvType;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_spr)
    TextView tvSpr;
    @BindView(R.id.tv_user_name)
    TextView tvUserName;
    @BindView(R.id.tv_now_day_time)
    TextView tvNowDayTime;
    @BindView(R.id.edit_content)
    NumberEditText editContent;
    @BindView(R.id.tv_cb)
    TextView tvCb;
    ChosePicAdapter adapter;
    public static final String tag = "ReimbursementDspActivityActivity";
    @BindView(R.id.iv_select_spr)
    ImageView iv_select_spr;

    @Override
    protected void init() {
        ReimbursementDspActivityActivity__JumpCenter.bind(this);

        if (data.getImages()!= null && !data.getImages().isEmpty()){
            recycerPic.setLayoutManager(new GridLayoutManager(this, CHOSE_PIC_SPAN_COUNT));
            adapter = new ChosePicAdapter(data.getImages(), this,false);
            recycerPic.setAdapter(adapter);
        }
        tvUserName.setText(UserRequest.getInstance().getUser().getUser().getUName());
        tvNowDayTime.setText(data.getIntime());
        editContent.setText(data.getBody());
        tvSpr.setText(ChosePeopleActivity.getPeoplesInfos(data.getAuditor()));
        tvType.setText(LeaveTypeData.getInstance().getBxTypeList().get(data.getType() -1).getName());
        tvTime.setText(data.getCostDate());
        tvCb.setEnabled(!data.isUrge());
        tvSpr.setText(ChosePeopleActivity.getPeoplesInfos(data.getAuditor()));
        iv_select_spr.setVisibility(View.GONE);
    }
    /**
     * 删除。
     */
    @OnClick(R.id.tv_cx)
    void delete() {
        HttpHeper.get().toolService()
                .toolDelete("Evection/deleteByIdAuditEvection.do", id)
                .compose(bindToLifecycle()).compose(getThread())
                .subscribe(new CommonCallBack<String>(true,this) {
                    @Override
                    public void onCallBackSuccess(String data) {
                        LoadSuccessAndFailDialog.showSuccess(ReimbursementDspActivityActivity.this,data);
                        finish();
                    }
                });
    }

    /**
     * 催办
     */
    @OnClick(R.id.tv_cb)
    void cb() {
        HttpHeper.get().toolService()
                .cb(ChosePeopleActivity.getIdList(data.getAuditor()).toString(),id)
                .compose(bindToLifecycle()).compose(getThread())
                .subscribe(new CommonCallBack<String>(true,this) {
                    @Override
                    public void onCallBackSuccess(String data) {
                        LoadSuccessAndFailDialog.showSuccess(ReimbursementDspActivityActivity.this,data);
                        tvCb.setEnabled(false);
                    }
                });
    }
}
